package com.example.fq.s3;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.SearchView;
import android.widget.Toast;

/**
 * Created by fq on 15-5-11.
 */
public class SearchTitleLayout extends LinearLayout  implements SearchView.OnQueryTextListener{
    private SearchView searchView;

    public SearchTitleLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.search_title, this);


        searchView = (SearchView) findViewById(R.id.query);
        searchView.setOnQueryTextListener(this);

    }

    @Override
    public boolean onQueryTextSubmit(String query) {
        HttpUtil.sendHttpRequest(query, new HttpCallbackListener() {
            @Override
            public void onFinish(String response) {
                MainActivity mainActivity = (MainActivity) getContext();
                CarFragment carFragment = (CarFragment) mainActivity.getFragmentManager()
.findFragmentById(R.id.car_fragment);
                carFragment.refresh(response);
            }

            @Override
            public void onError(Exception e) {
                e.printStackTrace();

            }


        });
//        Toast.makeText(getContext(), query, Toast.LENGTH_SHORT).show();
        return false;
    }

    @Override
    public boolean onQueryTextChange(String query) {
        return false;
    }


}
